Load all required libraries.
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.8
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(broom)
Read in raw data from RDS.
raw_data <- readRDS("./n1_n2_cleaned_cases.rds")
Make a few small modifications to names and data for visualizations.
final_data <- raw_data %>% mutate(log_copy_per_L = log10(mean_copy_num_L)) %>%
rename(Facility = wrf) %>%
mutate(Facility = recode(Facility,
"NO" = "WRF A",
"MI" = "WRF B",
"CC" = "WRF C"))
Seperate the data by gene target to ease layering in the final plot
#make three data layers
only_positives <<- subset(final_data, (!is.na(final_data$Facility)))
only_n1 <- subset(only_positives, target == "N1")
only_n2 <- subset(only_positives, target == "N2")
only_background <<-final_data %>%
select(c(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke)) %>%
group_by(date) %>% summarise_if(is.numeric, mean)
#specify fun colors
background_color <- "#7570B3"
seven_day_ave_color <- "#E6AB02"
marker_colors <- c("N1" = '#1B9E77',"N2" ='#D95F02')
#remove facilty C for now
#only_n1 <- only_n1[!(only_n1$Facility == "WRF C"),]
#only_n2 <- only_n2[!(only_n2$Facility == "WRF C"),]
only_n1 <- only_n1[!(only_n1$Facility == "WRF A" & only_n1$date == "2020-11-02"), ]
only_n2 <- only_n2[!(only_n2$Facility == "WRF A" & only_n2$date == "2020-11-02"), ]
Build the main plot
#first layer is the background epidemic curve
p1 <- only_background %>%
plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~new_cases_clarke,
type = "bar",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Daily Cases: ', new_cases_clarke),
alpha = 0.5,
name = "Daily Reported Cases",
color = background_color,
colors = background_color,
showlegend = FALSE) %>%
layout(yaxis = list(title = "Clarke County Daily Cases", showline=TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#renders the main plot layer two as seven day moving average
p1 <- p1 %>% plotly::add_trace(x = ~date, y = ~X7_day_ave_clarke,
type = "scatter",
mode = "lines",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Seven-Day Moving Average: ', X7_day_ave_clarke),
name = "Seven Day Moving Average Athens",
line = list(color = seven_day_ave_color),
showlegend = FALSE)
#renders the main plot layer three as positive target hits
p2 <- plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n1,
symbol = ~Facility,
marker = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n2,
symbol = ~Facility,
marker = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(yaxis = list(title = "SARS CoV-2 Copies/L",
showline = TRUE,
type = "log",
dtick = 1,
automargin = TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#adds the limit of detection dashed line
p2 <- p2 %>% plotly::add_segments(x = as.Date("2020-03-14"),
xend = ~max(date + 10),
y = 3571.429, yend = 3571.429,
opacity = 0.35,
line = list(color = "black", dash = "dash")) %>%
layout(annotations = list(x = as.Date("2020-03-28"), y = 3.8, xref = "x", yref = "y",
text = "Limit of Detection", showarrow = FALSE))
p1
p2
Combine the two main plot pieces as a subplot
#seperate n1 and n2 frames by site
#n1
wrf_a_only_n1 <- subset(only_n1, Facility == "WRF A")
wrf_b_only_n1 <- subset(only_n1, Facility == "WRF B")
wrf_c_only_n1 <- subset(only_n1, Facility == "WRF C")
#n2
wrf_a_only_n2 <- subset(only_n2, Facility == "WRF A")
wrf_b_only_n2 <- subset(only_n2, Facility == "WRF B")
wrf_c_only_n2 <- subset(only_n2, Facility == "WRF C")
#rejoin the old data frames then seperate in to averages for each plant.
wrfa_both <- full_join(wrf_a_only_n1, wrf_a_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfb_both <- full_join(wrf_b_only_n1, wrf_b_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfc_both <- full_join(wrf_c_only_n1, wrf_c_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
#get max date
maxdate <- max(wrfa_both$date)
mindate <- min(wrfa_both$date)
Build loess smoothing figures figures
This makes the individual plots
#**************************************WRF A PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_botha <- ggplot(wrfa_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_botha<<-..y..), method = "loess", color = '#1B9E77',
span = 0.25, n = 884)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_botha
## `geom_smooth()` using formula 'y ~ x'
fit_botha
## [1] 13.03228 13.02818 13.02412 13.02010 13.01613 13.01220 13.00831 13.00447
## [9] 13.00068 12.99693 12.99322 12.98956 12.98594 12.98237 12.97884 12.97536
## [17] 12.97193 12.96853 12.96519 12.96188 12.95863 12.95542 12.95225 12.94913
## [25] 12.94605 12.94302 12.94004 12.93710 12.93420 12.93136 12.92855 12.92580
## [33] 12.92309 12.92042 12.91780 12.91523 12.91270 12.91022 12.90779 12.90540
## [41] 12.90306 12.90076 12.89851 12.89632 12.89420 12.89215 12.89016 12.88825
## [49] 12.88640 12.88462 12.88290 12.88125 12.87966 12.87813 12.87666 12.87526
## [57] 12.87391 12.87263 12.87140 12.87023 12.86912 12.86806 12.86706 12.86611
## [65] 12.86522 12.86437 12.86358 12.86284 12.86215 12.86151 12.86091 12.86037
## [73] 12.85987 12.85941 12.85901 12.85864 12.85832 12.85804 12.85780 12.85760
## [81] 12.85744 12.85732 12.85724 12.85719 12.85718 12.85721 12.85727 12.85737
## [89] 12.85749 12.85765 12.85784 12.85807 12.85834 12.85870 12.85914 12.85965
## [97] 12.86024 12.86090 12.86163 12.86243 12.86329 12.86422 12.86521 12.86626
## [105] 12.86737 12.86853 12.86975 12.87102 12.87234 12.87370 12.87511 12.87657
## [113] 12.87806 12.87960 12.88117 12.88277 12.88441 12.88608 12.88778 12.88951
## [121] 12.89126 12.89303 12.89482 12.89663 12.89846 12.90030 12.90215 12.90401
## [129] 12.90588 12.90776 12.90964 12.91152 12.91340 12.91528 12.91715 12.91973
## [137] 12.92367 12.92884 12.93514 12.94245 12.95066 12.95965 12.96933 12.97957
## [145] 12.99025 13.00128 13.01253 13.02390 13.03526 13.04652 13.05755 13.06824
## [153] 13.07849 13.08817 13.09719 13.10541 13.11274 13.11905 13.12424 13.12820
## [161] 13.13081 13.13307 13.13604 13.13966 13.14387 13.14862 13.15386 13.15952
## [169] 13.16555 13.17190 13.17852 13.18534 13.19232 13.19939 13.20651 13.21362
## [177] 13.22066 13.22757 13.23431 13.24082 13.24704 13.25292 13.25840 13.26343
## [185] 13.26795 13.27191 13.27525 13.27792 13.27986 13.28102 13.28134 13.28076
## [193] 13.27925 13.27672 13.27314 13.26845 13.26247 13.25514 13.24656 13.23682
## [201] 13.22602 13.21428 13.20168 13.18833 13.17433 13.15978 13.14478 13.12943
## [209] 13.11383 13.09808 13.08229 13.06655 13.05097 13.03563 13.02066 13.00614
## [217] 12.99217 12.97886 12.96631 12.95312 12.93791 12.92086 12.90210 12.88181
## [225] 12.86013 12.83723 12.81325 12.78835 12.76269 12.73643 12.70972 12.68271
## [233] 12.65557 12.62845 12.60150 12.57488 12.54874 12.52325 12.49856 12.47483
## [241] 12.45220 12.43084 12.41090 12.39254 12.37591 12.36005 12.34392 12.32755
## [249] 12.31097 12.29422 12.27734 12.26036 12.24332 12.22624 12.20918 12.19215
## [257] 12.17520 12.15837 12.14168 12.12517 12.10888 12.09284 12.07709 12.06166
## [265] 12.04659 12.03191 12.01766 12.00387 11.99087 11.97890 11.96788 11.95775
## [273] 11.94843 11.93986 11.93197 11.92467 11.91790 11.91160 11.90568 11.90008
## [281] 11.89472 11.88954 11.88446 11.87941 11.87432 11.86912 11.86374 11.85810
## [289] 11.85214 11.84578 11.83896 11.83159 11.82362 11.81496 11.80561 11.79565
## [297] 11.78516 11.77420 11.76286 11.75121 11.73932 11.72727 11.71513 11.70298
## [305] 11.69089 11.67893 11.66719 11.65573 11.64463 11.63397 11.62381 11.61424
## [313] 11.60532 11.59714 11.58976 11.58327 11.57773 11.57206 11.56523 11.55736
## [321] 11.54856 11.53898 11.52872 11.51792 11.50671 11.49520 11.48352 11.47181
## [329] 11.46017 11.44875 11.43765 11.42702 11.41697 11.40763 11.39912 11.39157
## [337] 11.38511 11.37986 11.37594 11.37349 11.37261 11.37345 11.37613 11.38012
## [345] 11.38481 11.39016 11.39615 11.40275 11.40995 11.41770 11.42599 11.43479
## [353] 11.44407 11.45381 11.46397 11.47454 11.48548 11.49678 11.50840 11.52032
## [361] 11.53251 11.54494 11.55759 11.57043 11.58344 11.59659 11.61144 11.62943
## [369] 11.65030 11.67384 11.69980 11.72795 11.75806 11.78990 11.82322 11.85779
## [377] 11.89339 11.92977 11.96670 12.00394 12.04127 12.07845 12.11524 12.15141
## [385] 12.18672 12.22094 12.25384 12.28518 12.31473 12.34224 12.36750 12.39026
## [393] 12.41029 12.42736 12.44326 12.45988 12.47714 12.49494 12.51319 12.53181
## [401] 12.55069 12.56974 12.58889 12.60802 12.62706 12.64590 12.66447 12.68266
## [409] 12.70039 12.71756 12.73409 12.74987 12.76482 12.77885 12.79187 12.80378
## [417] 12.81450 12.82392 12.83197 12.83854 12.84353 12.84698 12.84898 12.84966
## [425] 12.84913 12.84750 12.84488 12.84139 12.83713 12.83223 12.82678 12.82091
## [433] 12.81473 12.80834 12.80187 12.79542 12.78911 12.78304 12.77734 12.77211
## [441] 12.76747 12.76352 12.76039 12.75647 12.75022 12.74183 12.73148 12.71936
## [449] 12.70565 12.69054 12.67421 12.65684 12.63864 12.61977 12.60043 12.58079
## [457] 12.56106 12.54140 12.52201 12.50308 12.48478 12.46730 12.45084 12.43556
## [465] 12.42167 12.40934 12.39876 12.39012 12.38360 12.37757 12.37035 12.36210
## [473] 12.35292 12.34297 12.33236 12.32123 12.30972 12.29796 12.28607 12.27419
## [481] 12.26246 12.25099 12.23994 12.22942 12.21958 12.21053 12.20243 12.19539
## [489] 12.18954 12.18503 12.18199 12.18053 12.18086 12.18299 12.18682 12.19222
## [497] 12.19910 12.20734 12.21682 12.22745 12.23910 12.25168 12.26506 12.27914
## [505] 12.29381 12.30895 12.32446 12.34022 12.35613 12.37208 12.38795 12.40363
## [513] 12.41901 12.43399 12.44845 12.46228 12.47537 12.48761 12.49889 12.50910
## [521] 12.51813 12.52587 12.53220 12.53702 12.54022 12.54302 12.54667 12.55109
## [529] 12.55619 12.56191 12.56816 12.57486 12.58193 12.58930 12.59688 12.60460
## [537] 12.61238 12.62013 12.62779 12.63526 12.64248 12.64935 12.65581 12.66178
## [545] 12.66717 12.67190 12.67590 12.67909 12.68139 12.68272 12.68299 12.68214
## [553] 12.68009 12.67674 12.67203 12.66567 12.65750 12.64767 12.63631 12.62356
## [561] 12.60955 12.59443 12.57832 12.56136 12.54369 12.52544 12.50676 12.48778
## [569] 12.46863 12.44945 12.43038 12.41155 12.39310 12.37516 12.35788 12.34138
## [577] 12.32581 12.31130 12.29799 12.28601 12.27550 12.26450 12.25113 12.23560
## [585] 12.21816 12.19903 12.17845 12.15664 12.13384 12.11028 12.08619 12.06180
## [593] 12.03734 12.01304 11.98914 11.96586 11.94343 11.92210 11.90208 11.88361
## [601] 11.86691 11.85223 11.83980 11.82983 11.82082 11.81113 11.80085 11.79008
## [609] 11.77889 11.76736 11.75559 11.74366 11.73165 11.71965 11.70774 11.69601
## [617] 11.68454 11.67342 11.66274 11.65257 11.64301 11.63413 11.62603 11.61878
## [625] 11.61248 11.60721 11.60305 11.60008 11.59840 11.59809 11.59968 11.60354
## [633] 11.60948 11.61734 11.62694 11.63809 11.65064 11.66439 11.67919 11.69484
## [641] 11.71117 11.72802 11.74520 11.76254 11.77986 11.79699 11.81375 11.82997
## [649] 11.84547 11.86007 11.87360 11.88589 11.89675 11.90767 11.92016 11.93411
## [657] 11.94938 11.96588 11.98348 12.00206 12.02151 12.04172 12.06255 12.08391
## [665] 12.10566 12.12770 12.14991 12.17217 12.19436 12.21637 12.23808 12.25937
## [673] 12.28012 12.30023 12.31957 12.33802 12.35548 12.37181 12.38691 12.40066
## [681] 12.41294 12.42445 12.43597 12.44747 12.45895 12.47039 12.48177 12.49307
## [689] 12.50429 12.51541 12.52642 12.53730 12.54803 12.55860 12.56899 12.57920
## [697] 12.58920 12.59898 12.60853 12.61784 12.62687 12.63564 12.64410 12.65227
## [705] 12.66010 12.66761 12.67476 12.68147 12.68769 12.69345 12.69879 12.70375
## [713] 12.70835 12.71263 12.71662 12.72037 12.72391 12.72726 12.73047 12.73357
## [721] 12.73660 12.73958 12.74256 12.74557 12.74864 12.75180 12.75511 12.75858
## [729] 12.76225 12.76616 12.77007 12.77374 12.77718 12.78039 12.78339 12.78617
## [737] 12.78876 12.79116 12.79338 12.79543 12.79732 12.79906 12.80065 12.80210
## [745] 12.80343 12.80465 12.80575 12.80676 12.80768 12.80852 12.80929 12.81000
## [753] 12.81065 12.81126 12.81183 12.81238 12.81276 12.81285 12.81267 12.81223
## [761] 12.81155 12.81067 12.80959 12.80834 12.80695 12.80543 12.80379 12.80208
## [769] 12.80030 12.79847 12.79662 12.79477 12.79293 12.79114 12.78941 12.78776
## [777] 12.78621 12.78478 12.78350 12.78209 12.78026 12.77807 12.77554 12.77270
## [785] 12.76958 12.76622 12.76265 12.75891 12.75501 12.75101 12.74692 12.74278
## [793] 12.73863 12.73450 12.73041 12.72641 12.72252 12.71878 12.71522 12.71186
## [801] 12.70875 12.70592 12.70340 12.70121 12.69941 12.69800 12.69704 12.69626
## [809] 12.69541 12.69448 12.69351 12.69249 12.69145 12.69038 12.68931 12.68825
## [817] 12.68720 12.68619 12.68522 12.68430 12.68344 12.68267 12.68198 12.68139
## [825] 12.68092 12.68058 12.68037 12.68031 12.68041 12.68069 12.68115 12.68181
## [833] 12.68268 12.68368 12.68471 12.68579 12.68692 12.68809 12.68933 12.69062
## [841] 12.69197 12.69339 12.69488 12.69645 12.69809 12.69982 12.70163 12.70353
## [849] 12.70553 12.70762 12.70982 12.71212 12.71453 12.71705 12.71969 12.72245
## [857] 12.72534 12.72838 12.73155 12.73486 12.73831 12.74188 12.74558 12.74940
## [865] 12.75335 12.75742 12.76160 12.76589 12.77030 12.77481 12.77943 12.78415
## [873] 12.78897 12.79388 12.79889 12.80399 12.80917 12.81444 12.81980 12.82523
## [881] 12.83074 12.83632 12.84197 12.84769
#assign fits to a vector
both_trenda <- fit_botha
#extract y min and max for each
limits_botha <- ggplot_build(extract_botha)$data
## `geom_smooth()` using formula 'y ~ x'
limits_botha <- as.data.frame(limits_botha)
both_ymina <- limits_botha$ymin
both_ymaxa <- limits_botha$ymax
#reassign dataframes (just to be safe)
work_botha <- wrfa_both
#fill in missing dates to smooth fits
work_botha <- work_botha %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_botha <- work_botha$date
#create a new smooth dataframe to layer
smooth_frame_botha <- data.frame(date_vec_botha, both_trenda, both_ymina, both_ymaxa)
#WRF A
#plot smooth frames
p_wrf_a <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_botha, y = ~both_trenda,
data = smooth_frame_botha,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha,
'</br> Median Log Copies: ', round(both_trenda, digits = 2)),
line = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_botha, ymin = ~both_ymina, ymax = ~both_ymaxa,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxa, digits = 2),
'</br> Min Log Copies: ', round(both_ymina, digits = 2)),
name = "",
fillcolor = '#1B9E77',
line = list(color = '#1B9E77')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF A") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfa_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#1B9E77', size = 6, opacity = 0.65))
p_wrf_a
save(p_wrf_a, file = "./plotly_objs/p_wrf_a.rda")
#**************************************WRF B PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothb <- ggplot(wrfb_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothb<<-..y..), method = "loess", color = '#D95F02',
span = 0.25, n = 884)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothb
## `geom_smooth()` using formula 'y ~ x'
fit_bothb
## [1] 12.56226 12.56010 12.55798 12.55592 12.55392 12.55196 12.55006 12.54822
## [9] 12.54643 12.54469 12.54302 12.54139 12.53983 12.53832 12.53687 12.53548
## [17] 12.53415 12.53287 12.53166 12.53050 12.52941 12.52838 12.52740 12.52649
## [25] 12.52565 12.52486 12.52414 12.52348 12.52288 12.52235 12.52188 12.52148
## [33] 12.52114 12.52087 12.52067 12.52053 12.52046 12.52046 12.52053 12.52066
## [41] 12.52087 12.52114 12.52148 12.52190 12.52238 12.52294 12.52356 12.52426
## [49] 12.52503 12.52588 12.52682 12.52788 12.52905 12.53033 12.53171 12.53321
## [57] 12.53481 12.53650 12.53830 12.54019 12.54217 12.54425 12.54641 12.54866
## [65] 12.55099 12.55339 12.55588 12.55844 12.56108 12.56378 12.56655 12.56938
## [73] 12.57228 12.57524 12.57825 12.58132 12.58443 12.58760 12.59082 12.59407
## [81] 12.59737 12.60071 12.60409 12.60750 12.61094 12.61440 12.61790 12.62142
## [89] 12.62495 12.62851 12.63208 12.63567 12.63927 12.64287 12.64648 12.65009
## [97] 12.65371 12.65732 12.66092 12.66470 12.66883 12.67327 12.67803 12.68306
## [105] 12.68837 12.69393 12.69971 12.70571 12.71190 12.71826 12.72477 12.73143
## [113] 12.73820 12.74506 12.75201 12.75902 12.76606 12.77313 12.78021 12.78727
## [121] 12.79430 12.80127 12.80817 12.81498 12.82169 12.82826 12.83469 12.84095
## [129] 12.84703 12.85290 12.85856 12.86397 12.86912 12.87399 12.87857 12.88349
## [137] 12.88936 12.89610 12.90361 12.91181 12.92062 12.92995 12.93971 12.94982
## [145] 12.96019 12.97074 12.98138 12.99202 13.00259 13.01299 13.02313 13.03294
## [153] 13.04233 13.05121 13.05949 13.06709 13.07393 13.07991 13.08496 13.08898
## [161] 13.09189 13.09455 13.09782 13.10166 13.10602 13.11084 13.11608 13.12167
## [169] 13.12758 13.13375 13.14012 13.14665 13.15329 13.15999 13.16669 13.17334
## [177] 13.17989 13.18629 13.19249 13.19844 13.20408 13.20937 13.21426 13.21869
## [185] 13.22261 13.22597 13.22872 13.23081 13.23218 13.23280 13.23259 13.23152
## [193] 13.22954 13.22658 13.22260 13.21756 13.21071 13.20151 13.19014 13.17681
## [201] 13.16172 13.14506 13.12703 13.10784 13.08768 13.06674 13.04524 13.02336
## [209] 13.00130 12.97927 12.95746 12.93607 12.91530 12.89535 12.87641 12.85869
## [217] 12.84238 12.82768 12.81479 12.80197 12.78743 12.77130 12.75374 12.73487
## [225] 12.71485 12.69382 12.67191 12.64926 12.62602 12.60234 12.57834 12.55417
## [233] 12.52998 12.50590 12.48207 12.45865 12.43575 12.41354 12.39215 12.37172
## [241] 12.35239 12.33430 12.31760 12.30242 12.28891 12.27663 12.26499 12.25395
## [249] 12.24346 12.23346 12.22392 12.21477 12.20597 12.19747 12.18921 12.18115
## [257] 12.17324 12.16542 12.15765 12.14988 12.14205 12.13411 12.12602 12.11772
## [265] 12.10917 12.10031 12.09110 12.08148 12.07232 12.06446 12.05780 12.05224
## [273] 12.04768 12.04402 12.04117 12.03903 12.03749 12.03647 12.03585 12.03555
## [281] 12.03545 12.03548 12.03552 12.03547 12.03525 12.03475 12.03386 12.03251
## [289] 12.03057 12.02796 12.02458 12.02033 12.01511 12.00882 12.00161 11.99374
## [297] 11.98528 11.97630 11.96687 11.95704 11.94691 11.93652 11.92595 11.91527
## [305] 11.90454 11.89384 11.88323 11.87278 11.86256 11.85264 11.84308 11.83396
## [313] 11.82534 11.81729 11.80988 11.80318 11.79725 11.79076 11.78242 11.77243
## [321] 11.76095 11.74815 11.73422 11.71933 11.70365 11.68736 11.67063 11.65365
## [329] 11.63657 11.61959 11.60286 11.58658 11.57091 11.55604 11.54212 11.52935
## [337] 11.51789 11.50792 11.49961 11.49315 11.48870 11.48645 11.48655 11.48826
## [345] 11.49065 11.49372 11.49742 11.50173 11.50663 11.51210 11.51810 11.52460
## [353] 11.53159 11.53904 11.54691 11.55519 11.56385 11.57286 11.58219 11.59182
## [361] 11.60173 11.61188 11.62225 11.63282 11.64355 11.65443 11.66681 11.68196
## [369] 11.69967 11.71974 11.74196 11.76615 11.79209 11.81958 11.84842 11.87842
## [377] 11.90937 11.94106 11.97331 12.00589 12.03863 12.07130 12.10372 12.13567
## [385] 12.16697 12.19740 12.22677 12.25487 12.28151 12.30648 12.32958 12.35060
## [393] 12.36936 12.38564 12.40136 12.41849 12.43688 12.45637 12.47683 12.49810
## [401] 12.52005 12.54251 12.56535 12.58842 12.61156 12.63465 12.65752 12.68003
## [409] 12.70204 12.72339 12.74394 12.76355 12.78206 12.79934 12.81522 12.82957
## [417] 12.84225 12.85309 12.86196 12.86871 12.87355 12.87688 12.87880 12.87941
## [425] 12.87882 12.87715 12.87449 12.87095 12.86665 12.86168 12.85616 12.85019
## [433] 12.84388 12.83733 12.83066 12.82396 12.81735 12.81094 12.80482 12.79911
## [441] 12.79391 12.78934 12.78549 12.78062 12.77306 12.76303 12.75074 12.73642
## [449] 12.72028 12.70255 12.68344 12.66317 12.64196 12.62004 12.59761 12.57490
## [457] 12.55213 12.52952 12.50728 12.48564 12.46482 12.44502 12.42649 12.40942
## [465] 12.39405 12.38058 12.36925 12.36027 12.35385 12.34815 12.34124 12.33326
## [473] 12.32435 12.31466 12.30431 12.29345 12.28222 12.27075 12.25919 12.24767
## [481] 12.23633 12.22532 12.21476 12.20479 12.19557 12.18721 12.17987 12.17369
## [489] 12.16879 12.16532 12.16342 12.16322 12.16484 12.16823 12.17328 12.17988
## [497] 12.18793 12.19733 12.20798 12.21976 12.23257 12.24632 12.26089 12.27618
## [505] 12.29209 12.30850 12.32533 12.34246 12.35979 12.37721 12.39462 12.41192
## [513] 12.42900 12.44575 12.46208 12.47787 12.49303 12.50745 12.52102 12.53364
## [521] 12.54521 12.55562 12.56477 12.57255 12.57885 12.58542 12.59393 12.60423
## [529] 12.61615 12.62955 12.64426 12.66011 12.67696 12.69465 12.71300 12.73187
## [537] 12.75110 12.77052 12.78997 12.80931 12.82836 12.84697 12.86498 12.88223
## [545] 12.89856 12.91382 12.92783 12.94045 12.95152 12.96087 12.96834 12.97379
## [553] 12.97703 12.97793 12.97632 12.97233 12.96631 12.95840 12.94874 12.93746
## [561] 12.92472 12.91065 12.89539 12.87908 12.86187 12.84390 12.82530 12.80621
## [569] 12.78679 12.76716 12.74748 12.72787 12.70849 12.68947 12.67095 12.65308
## [577] 12.63600 12.61984 12.60475 12.59087 12.57834 12.56475 12.54781 12.52783
## [585] 12.50515 12.48006 12.45289 12.42396 12.39359 12.36208 12.32977 12.29696
## [593] 12.26397 12.23112 12.19873 12.16712 12.13660 12.10749 12.08010 12.05476
## [601] 12.03178 12.01148 11.99417 11.98018 11.96732 11.95327 11.93817 11.92214
## [609] 11.90532 11.88784 11.86983 11.85142 11.83274 11.81392 11.79508 11.77637
## [617] 11.75791 11.73983 11.72227 11.70534 11.68920 11.67395 11.65974 11.64669
## [625] 11.63494 11.62461 11.61584 11.60876 11.60350 11.60018 11.59889 11.59955
## [633] 11.60200 11.60612 11.61178 11.61883 11.62715 11.63659 11.64702 11.65830
## [641] 11.67031 11.68290 11.69594 11.70929 11.72282 11.73639 11.74988 11.76313
## [649] 11.77602 11.78841 11.80017 11.81115 11.82123 11.83195 11.84483 11.85971
## [657] 11.87644 11.89488 11.91487 11.93625 11.95887 11.98258 12.00722 12.03265
## [665] 12.05870 12.08523 12.11209 12.13911 12.16615 12.19305 12.21966 12.24584
## [673] 12.27141 12.29624 12.32016 12.34303 12.36469 12.38498 12.40377 12.42088
## [681] 12.43618 12.45071 12.46563 12.48087 12.49641 12.51219 12.52818 12.54433
## [689] 12.56060 12.57695 12.59333 12.60970 12.62602 12.64224 12.65833 12.67423
## [697] 12.68992 12.70533 12.72044 12.73519 12.74955 12.76347 12.77692 12.78983
## [705] 12.80219 12.81393 12.82502 12.83560 12.84585 12.85578 12.86540 12.87474
## [713] 12.88379 12.89258 12.90111 12.90941 12.91748 12.92534 12.93299 12.94046
## [721] 12.94776 12.95490 12.96189 12.96875 12.97549 12.98212 12.98865 12.99511
## [729] 13.00150 13.00783 13.01410 13.02027 13.02634 13.03229 13.03812 13.04381
## [737] 13.04937 13.05477 13.06000 13.06507 13.06996 13.07465 13.07915 13.08344
## [745] 13.08750 13.09134 13.09495 13.09830 13.10140 13.10424 13.10679 13.10907
## [753] 13.11104 13.11272 13.11408 13.11512 13.11568 13.11565 13.11507 13.11398
## [761] 13.11243 13.11045 13.10810 13.10541 13.10243 13.09920 13.09577 13.09217
## [769] 13.08845 13.08466 13.08083 13.07702 13.07325 13.06959 13.06606 13.06271
## [777] 13.05959 13.05674 13.05420 13.05149 13.04815 13.04422 13.03975 13.03478
## [785] 13.02938 13.02359 13.01745 13.01102 13.00435 12.99748 12.99047 12.98336
## [793] 12.97621 12.96905 12.96195 12.95495 12.94810 12.94145 12.93505 12.92894
## [801] 12.92319 12.91782 12.91291 12.90849 12.90461 12.90133 12.89869 12.89631
## [809] 12.89381 12.89118 12.88846 12.88565 12.88277 12.87984 12.87687 12.87388
## [817] 12.87089 12.86790 12.86494 12.86202 12.85915 12.85636 12.85366 12.85106
## [825] 12.84858 12.84624 12.84405 12.84202 12.84018 12.83854 12.83711 12.83592
## [833] 12.83496 12.83414 12.83333 12.83253 12.83175 12.83099 12.83028 12.82960
## [841] 12.82897 12.82840 12.82790 12.82746 12.82710 12.82683 12.82665 12.82656
## [849] 12.82658 12.82672 12.82697 12.82735 12.82786 12.82852 12.82932 12.83028
## [857] 12.83140 12.83269 12.83414 12.83575 12.83752 12.83944 12.84150 12.84370
## [865] 12.84605 12.84852 12.85113 12.85387 12.85672 12.85970 12.86279 12.86599
## [873] 12.86929 12.87270 12.87620 12.87980 12.88349 12.88726 12.89111 12.89504
## [881] 12.89905 12.90312 12.90726 12.91147
#assign fits to a vector
both_trendb <- fit_bothb
#extract y min and max for each
limits_bothb <- ggplot_build(extract_bothb)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothb <- as.data.frame(limits_bothb)
both_yminb <- limits_bothb$ymin
both_ymaxb <- limits_bothb$ymax
#reassign dataframes (just to be safe)
work_bothb <- wrfb_both
#fill in missing dates to smooth fits
work_bothb <- work_bothb %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothb <- work_bothb$date
#create a new smooth dataframe to layer
smooth_frame_bothb <- data.frame(date_vec_bothb, both_trendb, both_yminb, both_ymaxb)
#WRF B
#plot smooth frames
p_wrf_b <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothb, y = ~both_trendb,
data = smooth_frame_bothb,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb,
'</br> Median Log Copies: ', round(both_trendb, digits = 2)),
line = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothb, ymin = ~both_yminb, ymax = ~both_ymaxb,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxb, digits = 2),
'</br> Min Log Copies: ', round(both_yminb, digits = 2)),
name = "",
fillcolor = '#D95F02',
line = list(color = '#D95F02')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF B") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfb_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#D95F02', size = 6, opacity = 0.65))
p_wrf_b
save(p_wrf_b, file = "./plotly_objs/p_wrf_b.rda")
#**************************************WRF C PLOT********************************************** #add trendlines #extract data from geom_smooth # *********************************span 0.6*********************************** #*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothc <- ggplot(wrfc_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothc<<-..y..), method = "loess", color = '#E7298A',
span = 0.25, n = 884)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothc
## `geom_smooth()` using formula 'y ~ x'
fit_bothc
## [1] 12.02275 12.01702 12.01138 12.00583 12.00036 11.99498 11.98968 11.98447
## [9] 11.97935 11.97431 11.96936 11.96449 11.95971 11.95502 11.95041 11.94589
## [17] 11.94146 11.93711 11.93285 11.92867 11.92458 11.92058 11.91667 11.91284
## [25] 11.90910 11.90544 11.90188 11.89840 11.89500 11.89170 11.88848 11.88535
## [33] 11.88230 11.87935 11.87648 11.87369 11.87100 11.86839 11.86587 11.86344
## [41] 11.86109 11.85883 11.85666 11.85458 11.85259 11.85068 11.84886 11.84713
## [49] 11.84549 11.84394 11.84249 11.84119 11.84002 11.83898 11.83807 11.83729
## [57] 11.83663 11.83610 11.83569 11.83540 11.83523 11.83517 11.83523 11.83539
## [65] 11.83567 11.83605 11.83654 11.83713 11.83782 11.83861 11.83949 11.84047
## [73] 11.84154 11.84271 11.84396 11.84529 11.84671 11.84821 11.84979 11.85145
## [81] 11.85319 11.85499 11.85687 11.85882 11.86084 11.86292 11.86506 11.86726
## [89] 11.86952 11.87184 11.87422 11.87664 11.87912 11.88164 11.88421 11.88683
## [97] 11.88948 11.89218 11.89491 11.89772 11.90065 11.90370 11.90686 11.91014
## [105] 11.91354 11.91704 11.92066 11.92439 11.92823 11.93218 11.93624 11.94040
## [113] 11.94467 11.94905 11.95353 11.95811 11.96280 11.96758 11.97247 11.97745
## [121] 11.98253 11.98771 11.99299 11.99835 12.00382 12.00937 12.01502 12.02075
## [129] 12.02658 12.03249 12.03850 12.04458 12.05076 12.05702 12.06336 12.07089
## [137] 12.08062 12.09236 12.10594 12.12117 12.13788 12.15590 12.17504 12.19512
## [145] 12.21598 12.23743 12.25929 12.28139 12.30355 12.32559 12.34733 12.36860
## [153] 12.38922 12.40901 12.42779 12.44539 12.46163 12.47633 12.48931 12.50040
## [161] 12.50941 12.51780 12.52707 12.53716 12.54799 12.55948 12.57157 12.58419
## [169] 12.59726 12.61071 12.62446 12.63845 12.65260 12.66685 12.68111 12.69532
## [177] 12.70940 12.72328 12.73689 12.75016 12.76301 12.77538 12.78719 12.79836
## [185] 12.80883 12.81852 12.82736 12.83528 12.84221 12.84807 12.85280 12.85631
## [193] 12.85854 12.85942 12.85886 12.85681 12.85257 12.84566 12.83627 12.82465
## [201] 12.81101 12.79556 12.77852 12.76013 12.74058 12.72011 12.69893 12.67726
## [209] 12.65532 12.63333 12.61151 12.59008 12.56926 12.54926 12.53031 12.51262
## [217] 12.49642 12.48192 12.46934 12.45682 12.44243 12.42632 12.40863 12.38952
## [225] 12.36911 12.34757 12.32503 12.30164 12.27754 12.25288 12.22780 12.20245
## [233] 12.17697 12.15151 12.12621 12.10122 12.07668 12.05274 12.02954 12.00723
## [241] 11.98594 11.96584 11.94705 11.92974 11.91403 11.89915 11.88422 11.86926
## [249] 11.85427 11.83928 11.82429 11.80931 11.79436 11.77945 11.76459 11.74979
## [257] 11.73507 11.72044 11.70590 11.69148 11.67718 11.66302 11.64901 11.63515
## [265] 11.62147 11.60798 11.59468 11.58159 11.56891 11.55679 11.54522 11.53415
## [273] 11.52357 11.51344 11.50372 11.49439 11.48543 11.47679 11.46844 11.46037
## [281] 11.45253 11.44490 11.43745 11.43014 11.42295 11.41585 11.40880 11.40177
## [289] 11.39474 11.38768 11.38055 11.37332 11.36597 11.35846 11.35080 11.34304
## [297] 11.33521 11.32733 11.31944 11.31157 11.30373 11.29597 11.28831 11.28079
## [305] 11.27342 11.26623 11.25927 11.25255 11.24611 11.23996 11.23416 11.22871
## [313] 11.22365 11.21901 11.21482 11.21111 11.20790 11.20423 11.19920 11.19295
## [321] 11.18561 11.17733 11.16823 11.15845 11.14813 11.13741 11.12642 11.11530
## [329] 11.10418 11.09320 11.08250 11.07221 11.06247 11.05342 11.04518 11.03791
## [337] 11.03173 11.02678 11.02320 11.02112 11.02068 11.02202 11.02527 11.03026
## [345] 11.03666 11.04438 11.05332 11.06338 11.07448 11.08651 11.09938 11.11300
## [353] 11.12727 11.14209 11.15737 11.17301 11.18892 11.20501 11.22117 11.23732
## [361] 11.25335 11.26918 11.28470 11.29982 11.31445 11.32849 11.34354 11.36114
## [369] 11.38110 11.40323 11.42732 11.45320 11.48065 11.50951 11.53956 11.57062
## [377] 11.60249 11.63498 11.66790 11.70105 11.73425 11.76729 11.79999 11.83215
## [385] 11.86359 11.89410 11.92349 11.95157 11.97815 12.00304 12.02604 12.04695
## [393] 12.06559 12.08177 12.09689 12.11244 12.12835 12.14458 12.16105 12.17769
## [401] 12.19445 12.21125 12.22805 12.24476 12.26132 12.27768 12.29377 12.30952
## [409] 12.32487 12.33976 12.35412 12.36788 12.38099 12.39337 12.40497 12.41572
## [417] 12.42556 12.43441 12.44223 12.44894 12.45464 12.45950 12.46359 12.46692
## [425] 12.46957 12.47156 12.47295 12.47378 12.47410 12.47396 12.47339 12.47244
## [433] 12.47117 12.46962 12.46782 12.46584 12.46371 12.46148 12.45919 12.45690
## [441] 12.45464 12.45247 12.45042 12.44742 12.44243 12.43562 12.42714 12.41714
## [449] 12.40577 12.39317 12.37952 12.36495 12.34962 12.33369 12.31729 12.30060
## [457] 12.28375 12.26690 12.25020 12.23381 12.21788 12.20256 12.18799 12.17434
## [465] 12.16176 12.15040 12.14040 12.13193 12.12513 12.11825 12.10957 12.09927
## [473] 12.08754 12.07458 12.06057 12.04572 12.03021 12.01423 11.99798 11.98165
## [481] 11.96542 11.94950 11.93406 11.91931 11.90544 11.89263 11.88109 11.87099
## [489] 11.86253 11.85591 11.85132 11.84894 11.84840 11.84913 11.85106 11.85412
## [497] 11.85824 11.86336 11.86939 11.87627 11.88393 11.89230 11.90130 11.91087
## [505] 11.92094 11.93142 11.94227 11.95339 11.96473 11.97620 11.98775 11.99930
## [513] 12.01077 12.02211 12.03323 12.04406 12.05455 12.06461 12.07417 12.08316
## [521] 12.09152 12.09917 12.10605 12.11207 12.11717 12.12254 12.12933 12.13744
## [529] 12.14674 12.15714 12.16851 12.18075 12.19375 12.20739 12.22156 12.23616
## [537] 12.25106 12.26617 12.28136 12.29652 12.31155 12.32634 12.34076 12.35472
## [545] 12.36809 12.38077 12.39265 12.40361 12.41354 12.42234 12.42988 12.43607
## [553] 12.44078 12.44391 12.44534 12.44559 12.44528 12.44443 12.44308 12.44126
## [561] 12.43899 12.43630 12.43324 12.42982 12.42608 12.42205 12.41776 12.41324
## [569] 12.40851 12.40362 12.39859 12.39345 12.38824 12.38297 12.37769 12.37243
## [577] 12.36720 12.36206 12.35701 12.35211 12.34737 12.34146 12.33317 12.32273
## [585] 12.31034 12.29622 12.28058 12.26365 12.24564 12.22677 12.20725 12.18729
## [593] 12.16713 12.14696 12.12701 12.10749 12.08862 12.07062 12.05370 12.03807
## [601] 12.02396 12.01159 12.00115 11.99288 11.98507 11.97596 11.96567 11.95433
## [609] 11.94207 11.92900 11.91525 11.90096 11.88623 11.87121 11.85602 11.84077
## [617] 11.82560 11.81063 11.79598 11.78179 11.76817 11.75525 11.74316 11.73202
## [625] 11.72196 11.71311 11.70558 11.69950 11.69500 11.69220 11.69118 11.69182
## [633] 11.69400 11.69759 11.70248 11.70852 11.71560 11.72358 11.73235 11.74177
## [641] 11.75172 11.76208 11.77270 11.78348 11.79428 11.80497 11.81544 11.82554
## [649] 11.83517 11.84418 11.85245 11.85987 11.86629 11.87286 11.88076 11.88987
## [657] 11.90010 11.91136 11.92354 11.93656 11.95031 11.96469 11.97960 11.99496
## [665] 12.01066 12.02660 12.04269 12.05883 12.07492 12.09087 12.10657 12.12193
## [673] 12.13686 12.15125 12.16500 12.17803 12.19023 12.20150 12.21175 12.22088
## [681] 12.22879 12.23604 12.24323 12.25036 12.25743 12.26445 12.27139 12.27827
## [689] 12.28508 12.29181 12.29847 12.30505 12.31155 12.31796 12.32429 12.33053
## [697] 12.33667 12.34272 12.34867 12.35452 12.36027 12.36591 12.37144 12.37686
## [705] 12.38217 12.38735 12.39242 12.39720 12.40154 12.40547 12.40903 12.41224
## [713] 12.41515 12.41779 12.42019 12.42237 12.42439 12.42626 12.42802 12.42970
## [721] 12.43135 12.43298 12.43464 12.43635 12.43815 12.44007 12.44215 12.44442
## [729] 12.44691 12.44965 12.45252 12.45539 12.45823 12.46105 12.46385 12.46660
## [737] 12.46932 12.47199 12.47461 12.47717 12.47967 12.48210 12.48446 12.48673
## [745] 12.48893 12.49103 12.49303 12.49493 12.49673 12.49841 12.49997 12.50141
## [753] 12.50272 12.50390 12.50493 12.50581 12.50658 12.50724 12.50782 12.50831
## [761] 12.50871 12.50904 12.50929 12.50948 12.50960 12.50965 12.50965 12.50960
## [769] 12.50949 12.50935 12.50916 12.50893 12.50867 12.50839 12.50808 12.50775
## [777] 12.50740 12.50705 12.50668 12.50620 12.50549 12.50457 12.50345 12.50216
## [785] 12.50070 12.49910 12.49737 12.49553 12.49360 12.49158 12.48950 12.48737
## [793] 12.48521 12.48304 12.48087 12.47872 12.47660 12.47454 12.47254 12.47062
## [801] 12.46881 12.46711 12.46554 12.46413 12.46287 12.46180 12.46093 12.46011
## [809] 12.45920 12.45821 12.45714 12.45600 12.45480 12.45355 12.45226 12.45093
## [817] 12.44958 12.44821 12.44684 12.44546 12.44410 12.44275 12.44142 12.44013
## [825] 12.43889 12.43770 12.43656 12.43550 12.43451 12.43361 12.43280 12.43209
## [833] 12.43150 12.43095 12.43039 12.42982 12.42924 12.42865 12.42806 12.42747
## [841] 12.42689 12.42632 12.42576 12.42522 12.42470 12.42420 12.42373 12.42329
## [849] 12.42288 12.42252 12.42219 12.42191 12.42168 12.42151 12.42139 12.42133
## [857] 12.42133 12.42141 12.42156 12.42177 12.42205 12.42239 12.42279 12.42324
## [865] 12.42375 12.42431 12.42493 12.42559 12.42630 12.42705 12.42784 12.42867
## [873] 12.42953 12.43043 12.43136 12.43233 12.43332 12.43433 12.43537 12.43642
## [881] 12.43750 12.43859 12.43969 12.44081
#assign fits to a vector
both_trendc <- fit_bothc
#extract y min and max for each
limits_bothc <- ggplot_build(extract_bothc)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothc <- as.data.frame(limits_bothc)
both_yminc <- limits_bothc$ymin
both_ymaxc <- limits_bothc$ymax
#reassign dataframes (just to be safe)
work_bothc <- wrfc_both
#fill in missing dates to smooth fits
work_bothc <- work_bothc %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothc <- work_bothc$date
#create a new smooth dataframe to layer
smooth_frame_bothc <- data.frame(date_vec_bothc, both_trendc, both_yminc, both_ymaxc)
#WRF C
#plot smooth frames
p_wrf_c <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothc, y = ~both_trendc,
data = smooth_frame_bothc,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc,
'</br> Median Log Copies: ', round(both_trendc, digits = 2)),
line = list(color = '#E7298A', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothc, ymin = ~both_yminc, ymax = ~both_ymaxc,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxc, digits = 2),
'</br> Min Log Copies: ', round(both_yminc, digits = 2)),
name = "",
fillcolor = '#E7298A',
line = list(color = '#E7298A')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF C") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfc_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#E7298A', size = 6, opacity = 0.65))
p_wrf_c
save(p_wrf_c, file = "./plotly_objs/p_wrf_c.rda")
save(wrfa_both, file = "./plotly_objs/wrfa_both.rda")
save(wrfb_both, file = "./plotly_objs/wrfb_both.rda")
save(wrfc_both, file = "./plotly_objs/wrfc_both.rda")
save(date_vec_botha, file = "./plotly_objs/date_vec_botha.rda")
save(date_vec_bothb, file = "./plotly_objs/date_vec_bothb.rda")
save(date_vec_bothc, file = "./plotly_objs/date_vec_bothc.rda")
save(both_ymina, file = "./plotly_objs/both_ymina.rda")
save(both_ymaxa, file = "./plotly_objs/both_ymaxa.rda")
save(both_yminb, file = "./plotly_objs/both_yminb.rda")
save(both_ymaxb, file = "./plotly_objs/both_ymaxb.rda")
save(both_yminc, file = "./plotly_objs/both_yminc.rda")
save(both_ymaxc, file = "./plotly_objs/both_ymaxc.rda")